<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Report;
use App\Models\Notice;
use App\Models\NoticeUser;
use DB;

class ReportController extends Controller
{
    public function index()
    {
    	$where = [];
    	$list = Report::where($where)->paginate(10);
    	return view('admin.report.index',compact('list'));
    }

    public function edit($id)
    {
    	$data = Report::find($id);
    	return view('admin.report.edit',compact('data'));
    }

    public function update($id,Request $request)
    {	
    	try {
    		DB::beginTransaction();
    		$data = Report::find($id);
	    	$data->status = 100;
	    	$data->feedback_msg = $request->feedback_msg;
	    	$data->save();

	    	$notice['title'] = '举报处理结果';
	    	$notice['describe'] = str_limit($request->feedback_msg,20);
	    	$notice['contents'] = $request->feedback_msg;
	    	$rs = Notice::create($notice);
	    	$nu['notice_id']  = $rs->id;
	    	$nu['to_user_id'] = $data->user_id;
	    	NoticeUser::create($nu);
	    	DB::commit();	
    	} catch (\Exception $e) {
    		DB::rollback();
    		dd($e->getMessage());

    	}

    	
    	return back();



    }
}
